<?php
/* 
-----------------------------------------------------------------
Copyright (c) 2010 25Solutions   All Rights Reserved.

This software is the confidential and proprietary information
of 25Solutions ("Confidential Information").
You shall not disclose such Confidential Information and shall
use it only in accordance with the terms of the license
agreement you entered into with 25Solutions
-----------------------------------------------------------------
 */

include(dirname(__FILE__).'/../../bootstrap/Doctrine.php');

$t = new lime_test(6);

//1
$t->comment('->countRecipientsForFilter()');
$count = Doctrine_Core::getTable('Recipient')->countRecipientsForFilter('');
$t->is($count, 103, "->countRecipientsForFilter() return $count recipients with empty filter ");
//2
$t->comment('->countRecipientsForFilter()');
$count = Doctrine_Core::getTable('Recipient')->countRecipientsForFilter("language = 'it'");
$t->is($count, 51, "->countRecipientsForFilter() return $count recipients with language = 'it' ");
//3
$t->comment('->getRecipientsForFilter()');
$recipients = Doctrine_Core::getTable('Recipient')->getRecipientsForFilter("language = 'it'", 3, 20);
$t->is($recipients->count(), 11, "->getRecipientsForFilter() return 11 recipients with language = 'it', page 3, pageSize 20 ");
//4
$t->comment('->getTargetRecipientsQuery()');
$q = Doctrine_Core::getTable('Recipient')->getTargetRecipientsQuery('username = \'fabiogmail\'', 'tag_mostre > 1');
//$t->is($q->getSqlQuery(), '', 'getTargetRecipientsQuery() returns correct query');
$t->is($q->count(), 1, '->getTargetRecipientsQuery(\'1 = 1\', \'tag_mostre > 1\') returns 1 recipient');
//5
$q = Doctrine_Core::getTable('Recipient')->getTargetRecipientsQuery('language = \'it\'');
$t->is($q->count(), 51, '->getTargetRecipientsQuery(\'language = \'it\'\') returns 51 recipients');
//6
$q = Doctrine_Core::getTable('Recipient')->getTargetRecipientsQuery(null, 'tag_mostre > 1');
$t->is($q->count(), 1, '->getTargetRecipientsQuery(null, \'tag_mostre > 1\') returns 1 recipient');